package com.md.model.word;

import lombok.Getter;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.FontsDocument;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author 刘骄阳
 * 2024-06-14 14:21
 */
@Getter
public class FontDocumentStyle extends BaseDocumentStyle {

  private final List<FontsDocument> fontsDocuments;

  public FontDocumentStyle() {
    super(XWPFRelation.FONT_TABLE);
    fontsDocuments = Lists.newArrayList();
  }

  public FontDocumentStyle(final XWPFDocument document) {
    super(XWPFRelation.FONT_TABLE);
    fontsDocuments = Lists.newArrayList();
    initStyleList(document);
  }

  @Override
  protected void setPartList(final POIXMLDocumentPart documentPart) throws IOException, XmlException {
    InputStream inputStream = documentPart.getPackagePart().getInputStream();
    FontsDocument fontsDocument = FontsDocument.Factory.parse(inputStream);
    fontsDocuments.add(fontsDocument);
  }

}
